
package com.example.editlist;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

public class PopListWindow extends PopupWindow {
    private View contentView;

    private static boolean mIsShown;
    
    private ListView lvResults;

    // 下拉列表项被单击的监听器
    // private OnItemClickListener listener;

    public PopListWindow(final Context context, LayoutInflater layoutInflater,

    final ArrayList<String> list, int width, OnItemClickListener itemClickListener) {
        super(context);

        // this.listener= itemClickListener;

        contentView = layoutInflater.inflate(R.layout.own_dropdown_list, null);
        lvResults = (ListView) contentView.findViewById(R.search_result_id.lvResults);
        PopListAdapter adapter = new PopListAdapter(context, list,
                layoutInflater);
        lvResults.setAdapter(adapter);

        // 如果PopupWindow中的下拉列表项被单击了

        // 则通知外部的下拉列表项单击监听器并传递当前单击项的数据
        lvResults.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) {
                Log.d("xxx", "onItemClick:"+index);
                // if(listener !=null){
                // Bundle data = new Bundle();
                // data.putString("address",
                //
                // ((TextView)view.findViewById(R.location_search_result_item_id.tvLocation))
                // .getText().toString().trim());
                //
                // if(listener != null)
                // listener.onClick(view, data);
                // dismiss();
                // }
            }
        });

        this.setContentView(contentView); // 设置悬浮窗体内显示的内容View
        this.setWidth(width - 5); // 设置悬浮窗体的宽度
        // this.setWidth(LayoutParams.WRAP_CONTENT);
        this.setHeight(LayoutParams.WRAP_CONTENT); // 设置悬浮窗体的高度
        this.setBackgroundDrawable(new ColorDrawable(0x00000000)); // 设置悬浮窗体背景
        // this.setAnimationStyle(R.style.PopupAnimation);
        this.setFocusable(true); // menu菜单获得焦点 如果没有获得焦点menu菜单中的控件事件无法响应
        this.setOutsideTouchable(true); // 可以再外部点击隐藏掉PopupWindow
        this.setTouchable(true);
    }
    

}
